package com.crealth.db;

import java.sql.Timestamp;
import java.util.List;
import org.apache.log4j.Logger;
import com.crealth.manager.MybatisManager;
import com.crealth.model.LoanContractModel;

public class LoanContractDb {
	private static Logger errorLog = Logger.getLogger("error_log");
	
	public static List<LoanContractModel> selectLoanContractByCompanyID(int companyID) {
		List<LoanContractModel> contractls = MybatisManager.contractMapper.selectLoanContractByCompanyID(companyID);
	
		return contractls;
	}
	
	public static List<LoanContractModel> selectAllLoanContract() {
		List<LoanContractModel> contractls = MybatisManager.contractMapper.selectAllLoanContract();
		
		return contractls;
	}
	
	public static List<Integer> selectAllConsumerIDs() {
		List<Integer> consumerIDs = MybatisManager.contractMapper.selectAllConsumerIDs();
		
		return consumerIDs;
	}
	
	public static Integer insertLoanContract(LoanContractModel contractModel) {
		Integer res = null;
		try {
			res = MybatisManager.contractMapper.insertLoanContract(contractModel);
		} catch (Exception e) {
			errorLog.error("insertLoanContract", e);
		}
		return res;
	}
	
	public static LoanContractModel selectLoanContractByID(
			int contractID) {
		LoanContractModel contract = MybatisManager.contractMapper.selectLoanContractByID(contractID);
		
		return contract;
	}
	
	public static List<LoanContractModel> selectLoanContractByConsumerID(
			int consumerID, int userID) {
		List<LoanContractModel> contractls = MybatisManager.contractMapper
				.selectLoanContractByConsumerID(consumerID, userID);
		
		return contractls;
	}
	
	public static List<LoanContractModel> selectLoanContractByIDs(String contractIDs) {
		List<LoanContractModel> contractls = MybatisManager.contractMapper.selectLoanContractByIDs(contractIDs);
		
		return contractls;
	}
	
	public static List<LoanContractModel> selectLoanContractNotProduct(String contractIDs) {
		List<LoanContractModel> contractls = MybatisManager.contractMapper.selectLoanContractNotProduct(contractIDs);
		
		return contractls;
	}
	
	public static List<Integer> selectConsumerInfoIDByIDs(String contractIDs) {
		List<Integer> consumerIDs = MybatisManager.contractMapper.selectConsumerInfoIDByIDs(contractIDs);
		
		return consumerIDs;
	}
	
	public static String selectMaxContractNo() {
		String maxNo = MybatisManager.contractMapper.selectMaxContractNo();
		
		return maxNo;
	}
	
	public static Integer updateContractByID(LoanContractModel contract) {
		Integer res = MybatisManager.contractMapper.updateContractByID(contract);
		MybatisManager.commit();
		
		return res;
	}
	
	//  修改  手续费、定金
	public static Integer updateExpenseEarnestByID(int contractID,
			String expenseValue, String earnestMoney) {
		Integer res = MybatisManager.contractMapper.updateExpenseEarnestByID(contractID, 
				expenseValue, earnestMoney);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer updateHasDelete(int contractID, int setDel) {
		Integer res = MybatisManager.contractMapper.updateHasDelete(contractID, setDel);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer updatePdfinfoUpload(int contractID, int setUpload) {
		Integer res = MybatisManager.contractMapper.updatePdfinfoUpload(contractID, setUpload);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer updateContractFileByID(int contractID, String strFileName) {
		Integer res = MybatisManager.contractMapper.updateContractFileByID(contractID, strFileName);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer updateFileCoverByID(int contractID, int fileCover) {
		Integer res = MybatisManager.contractMapper.updateFileCoverByID(contractID, fileCover);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer updateContractStatusByID(int contractID, int setStatus) {
		Integer res = MybatisManager.contractMapper.updateContractStatusByID(contractID, setStatus);
		MybatisManager.commit();
		
		return res;
	}
	
	public static List<LoanContractModel> selectAllErrorContract() {
		List<LoanContractModel> contractls = MybatisManager.contractMapper.selectAllErrorContract();
		
		return contractls;
	}
	
	public static Integer updateApplyForTmByID(int contractID, Timestamp setTm, String setContractNo) {
		Integer res = MybatisManager.contractMapper.updateApplyForTmByID(contractID, setTm, setContractNo);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer selectContractNoNum() {
		Integer res = MybatisManager.contractMapper.selectContractNoNum();
		
		return res;
	}
	
	public static Integer updateMaxContractNo(int maxContractNum) {
		Integer res = MybatisManager.contractMapper.updateMaxContractNo(maxContractNum);
		MybatisManager.commit();
		
		return res;
	}
	
	public static LoanContractModel selectContractByCondition(String strCondition) {
		LoanContractModel contract = MybatisManager.contractMapper.selectContractByCondition(strCondition);
		
		return contract;
	}
	
	public static Integer deleteContractByID(int contractID) {
		Integer res = MybatisManager.contractMapper.deleteContractByID(contractID);
		MybatisManager.commit();
		
		return res;
	}
	
	public static Integer selectConsumerContractNum(int consumerID) {
		Integer res = MybatisManager.contractMapper.selectConsumerContractNum(consumerID);
		
		return res;
	}
	
	public static List<Integer> selectHasContractConsumerID(String strConsumerIDs) {
		List<Integer> consumerIDs = MybatisManager.contractMapper.selectHasContractConsumerID(strConsumerIDs);
		
		return consumerIDs;
	}
	
	
}
